<template>
  <div>
    <div class="block">
      <span class="demonstration">预约时间</span>
      <el-date-picker v-model="neworder.ordertime"
                      type="datetime"
                      placeholder="选择日期时间">
      </el-date-picker>
    </div>
    顾客名：<el-input v-model="neworder.customer"></el-input>
    联系电话：<el-input v-model="neworder.phone"
              @blur="checkPhone"></el-input>
    服务地址：<el-input v-model="neworder.address"></el-input>
    <el-button type="success"
               @click="commit">确定</el-button>
    <el-button type="warning"
               @click="cancle">取消</el-button>
  </div>
</template>

<script>
export default {
  props: {
    updateOrer: {}
  },
  data () {
    return {
      neworder: {},
    }
  },
  methods: {
    commit () {
      this.$emit("closeupdatedialog", { result: true, data: this.neworder });
    },

    cancle () {
      this.$emit("closeupdatedialog", { result: false, data: {} });
    },
    checkPhone () {
      if (this.neworder.phone === '') {
        this.$message({
          type: 'error',
          message: '手机号不能为空'
        });
      } else {
        if (this.neworder.phone !== '') {
          var reg = /^1[3456789]\d{9}$/;
          if (!reg.test(this.neworder.phone)) {
            this.$message({
              type: 'error',
              message: '手机号不正确'
            });
          } else {
            this.$message({
              type: 'success',
              message: '手机号填写正确'
            });
          }
        }
      }
    }

  },
  mounted () {
    this.neworder = JSON.parse(JSON.stringify(this.updateOrer));
    this.neworder.time = null;
    this.neworder.createtime = null;
    console.log(this.neworder);
    console.log("updateHouse组件创建完毕");
  },

}
</script>

<style scoped>
</style>